

class Trace {
    traces = [];
	curIdx = -1;
	maxSteps = 300;

    /**
	 * 设置操作踪迹.
	 * @param params
	 */
	setTraces(params) {
		params = params ?? {};
		if (params.operation === undefined) params.operation = 'draw';
		if (
			params.index === undefined &&
			params.indexes === undefined
		) params.index = this.traces.length;
		if (this.curIdx !== this.traces.length - 1)
			this.traces = this.traces.slice(0, this.curIdx + 1);
		this.traces.push(params);
		this.curIdx = this.traces.length - 1;
		console.log('setTraces', this.traces);
		console.log('curIdx', this.curIdx);
	}

	undo() {
		this.curIdx = this.curIdx === -1 ? -1 : this.curIdx - 1;
		console.log('undo curIdx', this.curIdx);
	}

	redo() {
		this.curIdx = this.curIdx === this.traces.length - 1 ? this.traces.length - 1 : this.curIdx + 1;
		console.log('redo curIdx', this.curIdx);
	}

	clear() {
		this.traces = [];
		this.curIdx = -1;
	}
}

export {
    Trace,
}